#!/usr/bin/python
# Filename: 20.py
import os, sys
import email
import wave
path_sep = os.sep
pwd = sys.path[0]+path_sep
#step 1
fp = open(pwd+'resources'+path_sep+'20.in', 'r')
msg = email.message_from_file(fp)
fp.close()
for part in msg.walk():
	if(part.get_content_maintype() == 'multipart'):continue
	filename = part.get_filename()
	fp = open(pwd+'output'+path_sep+filename, 'wb')
	fp.write(part.get_payload(decode=True))
	
#step 2
w1 = wave.open(pwd+'output'+path_sep+'indian.wav', 'rb')
w2 = wave.open(pwd+'output'+path_sep+'indian2.wav', 'wb')

w2.setparams(w1.getparams())
data = w1.readframes(w1.getnframes())
for it1, it2 in zip(data[::2], data[1::2]):
	w2.writeframes(it2+it1)
w1.close(), w2.close()